package com.sq.partner.manager.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.dao.FacadeAppFormDao;
import com.sq.partner.manager.dao.FacadeAppInsuredDao;
import com.sq.partner.manager.dao.FacadeTempPolicyDao;
import com.sq.partner.manager.mybatis.model.FacadeAppForm;
import com.sq.partner.manager.service.FacadeAppApplicantService;
import com.sq.partner.manager.service.FacadeAppFormService;
import com.sq.partner.manager.service.FacadeAppInsuredService;
import com.sq.partner.manager.util.DateUtil;

/**
 * 投保单Service
 * 
 * @author zhouxiuxiu
 *
 */
@Service
public class FacadeAppFormServiceImpl implements FacadeAppFormService {

    @Resource
    FacadeAppFormDao facadeAppFormDao;
    @Resource
    FacadeAppInsuredService facadeAppInsuredService;
    @Resource
    FacadeAppApplicantService facadeAppApplicantService;
    @Resource
    FacadeAppInsuredDao facadeAppInsuredDao;

    @Resource
    FacadeTempPolicyDao facadeTempPolicyDao;

    /**
     * 添加投保单
     * 
     * @param facadeAppForm
     * @return
     * @throws Exception
     */
    @Override
    public FacadeAppForm saveFacadeAppForm(FacadeAppForm facadeAppForm)
            throws Exception {
        // 生成一个新的投保单号
        String newAppNo = facadeAppFormDao.queryNewAppNo();
        facadeAppForm.setAppNo(newAppNo);
        facadeAppForm.setCreatTime(DateUtil.getNowTimestamp());
        facadeAppForm.setUpdateTime(DateUtil.getNowTimestamp());
        facadeAppForm.setStatus(Constants.POL_STATUS_01);
        //添加投保单
        facadeAppFormDao.insertFacadeAppForm(facadeAppForm);
        return facadeAppForm;
    }

    /**
     * 保费试算完更新保费信息
     * @param facadeAppForm
     * @param facadeUser
     * @throws Exception
    */
    @Override
    public void updateFacadeAppForm(FacadeAppForm facadeAppForm) throws
            Exception {
        facadeAppFormDao.updateFacadeAppFormNotNull(facadeAppForm);
    }
    
    /**
     * 查询投保单
     * 
     * @param stagNo
     * @return
     */
    @Override
    public List<FacadeAppForm> getFacadeAppForm(String stagNo) throws Exception {
        FacadeAppForm facadeAppForm = new FacadeAppForm();
        facadeAppForm.setStagNo(stagNo);
        facadeAppForm.setStatus("'" + Constants.POL_STATUS_11 + "','"
                + Constants.POL_STATUS_13 + "'");
        return facadeAppFormDao.selectFacadeAppFormList(facadeAppForm);
    }
}
